package main

import (
	"fmt"
	"strconv"
	"time"
)

//时间和日期相关的函数
func main() {

	//获取当前时间

	now := time.Now()
	fmt.Printf("now value=%v  now type %T\n", now, now)

	//获取时间
	fmt.Printf("年 %v ", now.Year())
	fmt.Printf("月 %v ", int(now.Month()))
	fmt.Printf("日 %v ", now.Day())
	fmt.Printf("时 %v ", now.Hour())
	fmt.Printf("分 %v ", now.Minute())
	fmt.Printf("秒 %v ", now.Second())

	fmt.Println()
	//格式化日期时间
	strNow := fmt.Sprintf("%v-%v-%v %v:%v:%v", now.Year(),
		int(now.Month()), now.Day(), now.Hour(), now.Minute(), now.Second())

	//格式化日期时间 特定的参考时间  2006-01-02 15:04:05
	fmt.Println(strNow)
	fmt.Println(now.Format("2006-01-02 15:04:05"))
	fmt.Println(now.Format("2006-01-02"))
	fmt.Println(now.Format("15:04:05"))

	fmt.Println(now.Format("2006"))
	fmt.Println(now.Format("2006-01"))
	fmt.Println(now.Format("2006-1-02"))

	/*
		const (
		    Nanosecond  Duration = 1
		    Microsecond          = 1000 * Nanosecond
		    Millisecond          = 1000 * Microsecond
		    Second               = 1000 * Millisecond
		    Minute               = 60 * Second
		    Hour                 = 60 * Minute
		)
	*/

	//休眠的使用

	//i:=0
	//
	//for ;; {
	//	i++
	//	fmt.Println(i)
	//	time.Sleep(time.Millisecond*100)
	//
	//	if i==100 {
	//		break
	//	}
	//}

	//时间戳
	//unix 毫秒 UnixNano纳秒
	fmt.Printf("unix时间戳 %v,unixnano时间戳%v", now.Unix(), now.UnixNano())

	start := time.Now()

	str := ""
	for i := 0; i < 100000; i++ {
		str += "hello" + strconv.Itoa(i)
		fmt.Println("hello Golang", i)
	}

	fmt.Println(str)
	fmt.Println(time.Now().Sub(start))

}
